<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty wordwrap modifier plugin
 *
 * Type:     modifier<br>
 * Name:     wordwrap<br>
 * Purpose:  wrap a string of text at a given length
 * @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php
 *          wordwrap (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param integer
 * @param string
 * @param boolean
 * @return string
 */
function smarty_modifier_wordwrap_utf8($string,$length=80,$break="\n",$cut=false)
{
		$return = '';
    $br_width = mb_strlen($break, 'UTF-8');
    for($i = 0, $count = 0; $i < mb_strlen($string, 'UTF-8'); $i++, $count++)
    {
        if (mb_substr($string, $i, $br_width, 'UTF-8') == $break)
        {
            $count = 0;
            $return .= mb_substr($str, $i, $br_width, 'UTF-8');
            $i += $br_width - 1;
        }
        
        if ($count > $length)
        {
            $return .= $break;
            $count = 0;
        }
        
        $return .= mb_substr($string, $i, 1, 'UTF-8');
    }
    
    return $return;	
    //return wordwrap($string,$length,$break,$cut);
}

?>
